package com.example.demo.repository;

import com.example.demo.mode.PrintFileOperation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 21024
 */
@Mapper
public interface PrintFileOperationsMapper {
    @Select(" SELECT * FROM (" +
            "SELECT *, ROW_NUMBER() OVER (ORDER BY id) AS rownum " +
            "FROM printFileOperations \n" +
            "WHERE FileName LIKE CONCAT('%', #{fileName}, '%') " +
            ") AS numbered " +
            "WHERE rownum BETWEEN #{pageNum} + 1 AND #{pageNum} + #{pageSize}")
    List<PrintFileOperation> findByFileName(String fileName, int pageNum, int pageSize);

    @Select("SELECT COUNT(*) FROM printFileOperations WHERE FileName LIKE CONCAT('%', #{fileName}, '%')")
    int countByFileName(@Param("fileName") String fileName);

    @Select("SELECT * FROM printFileOperations WHERE FileName LIKE CONCAT('%', #{fileName}, '%')")
    List<PrintFileOperation> findAllFileName(String fileName);
}
